<template>
  <div class="components-container">
    <!-- 查询条件 -->
    <div class="header-form">
     <div class="layui-inline">
        <label>悼念厅名称</label>
         <div class="layui-input-inline">
            <el-input  v-model="selectData.memNameLike" placeholder="请输入悼念厅名称"></el-input>
         </div>
      </div>
     <div class="layui-inline">
        <label class="layui-form-label">类别</label>
         <div class="layui-input-inline">
            <el-select v-model="selectData.memCodNameLike" placeholder="请选择悼念厅类型">
              <el-option label="全部" :value="null"></el-option>
              <el-option v-for="item in memTypes" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
         </div>
      </div>
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button  @click="btnRepeat">重置</el-button>
    </div>
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>


    <!--数据列表-->
    <dataTable :headList="headList" :dataList="list" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    
    <MemorialMain ref="sweetModalMain" :orderType="order" @refreshData="getData"></MemorialMain>

    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.btnCenter {
  text-align: center;
}
</style>
<script>
import MemorialMain from "./MemorialMain";
import staEndUse from "./staEndUse";
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
export default {
  name: "Memorial",
  mixins: [manage],
  data() {
    return {
      list: [],
      loading: false,
      headList: [],
      btnListRow: [],
      infoList: [],
      memTypes: [],
      title: null,
      order: null,

      //分页和排序
      pageOrder: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: 10,
        currentPage: 1
      },
      //当前选中行
      currentRow: null,

      selectData:{
        memNameLike: null,
        memCodNameLike: null,
        memStatusEquals: null,
      },
      memName: null,
      memCodName: null,
    };
  },
  methods: {

//功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.$refs.sweetModalMain.open(this.order);
          break;
        case MODIFY:
        case INFO:
        case DELETE:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.MEMID);
          break;
        case ORDER.START:
        case ORDER.END:
          this.$refs.useMain.open(this.order, this.currentRow.MEMID);
          break;
        default:
      }
    },
    //获取列项
    getColumns() {
      apiBase.DoService(
        {},
        apiBase.getApiAdress().Column.GetMemorialColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取数据
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      var data = {
        PageIndex: this.$store.state.currentPage,
        PageSize: this.$store.state.pageSize,
        OrderBy: this.$store.state.orderType,
        OrderByType: this.$store.state.orderSort,
        Data: Data
      }
      apiBase.DoService(data, apiBase.getApiAdress().Memorial.Query, res => {
        this.list = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
    },
    //获取追悼厅类型
    getMemType() {
      apiBase.DoService(
        {},
        apiBase.getApiAdress().Code.GetMemorialType,
        res => {
          let memTypeData = res.data.content,
            legendsMemData = memTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue
            }));
          this.memTypes = legendsMemData;
        }
      );
    },
    //查询
    // btnSearch() {
    //   this.getData();
    // },
    //查询条件重置
    btnRepeat() {
      Object.assign(this.$data.selectData, this.$options.data().selectData);
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.MEMSTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFY:
        case DELETE:
          return status !== '';
          break;
        case ORDER.END:
          return status === 'A';
          break;
        case ORDER.START:
          return status === 'B';
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.memID = null;
      this.memName = null;
      this.memCodName = null;
      this.carPopedom = null;
      this.carStartDate = null;
      this.carIDEntificationCode = null;
      this.carBrand = null;
    },
    //分页和排序
    pageChange(value) {
      this.pageOrder = value;
      this.getData();
    },
    //获取当前选中行
    selectRow(row, order) {
      this.currentRow = row;
      if (order !== "") {
        this.operate(order);
      }
    }
  },
  mounted() {},
  computed: {},
  components: {
    MemorialMain,
    staEndUse,
    dataTable
  },
  created() {
    this.getColumns();
    this.getData();
    this.getMemType();
    for (var i in this.$store.state.btnListCommon) {
        let btnListCommon = this.$store.state.btnListCommon[i];
        if (btnListCommon.BTNVALUE === MODIFY || btnListCommon.BTNVALUE === DELETE) {
          this.btnListRow.push(btnListCommon);
        }
      }
  }
};
</script>